package movies.repositoryHibernate;

import java.util.List;
import movies.domain.Country;
import movies.repository.ICountryRepository;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author Hanna_Aliakseichykava
 */
public class CountryRepository extends HibernateDaoSupport
implements ICountryRepository{

    @Override
    public Country getCountryById(int id) {
        List < Country > countries = getHibernateTemplate().
             findByNamedQuery("GetCountryById", id);

        if (countries.size() == 1) {
            return countries.get(0);
        } else {
            return null;
        }
    }

    @Override
    public Country getCountryByName(String name) {
        List < Country > countries = getHibernateTemplate().
             findByNamedQuery("GetCountryByName", name);

        if (countries.size() == 1) {
            return countries.get(0);
        } else {
            return null;
        }
    }

    @Override
    public List<Country> getAllCountries() {
        List < Country > countries = getHibernateTemplate().
             findByNamedQuery("GetAllCountries");

        if (countries.size() > 0) {
            return countries;
        } else {
            return null;
        }
    }

}
